package com.lib76.socket.model;

import com.lib76.socket.Constants;
import com.lib76.socket.SocketObject;
import com.lib76.socket.SocketMessageProtocolManager;

/**
 * 接受报文事件
 * @author 张浩
 * @version 1.0.0
 */
public class ReceiveEvent {
	
	private SocketObject socketObject;
	private SocketChannel channel;
	private SocketMessage message;
	
	public ReceiveEvent(SocketObject socketObject,SocketChannel channel,SocketMessage message){
		this.socketObject = socketObject;
		this.channel = channel;
		this.message = message;
	}
	
	public SocketMessage getResponseMessage(){
		if(message.hasProtocol()){
			if(message.getProtocolObject().isRequest()){
				return SocketMessageProtocolManager.createSocketMessage(message.getProtocolObject().getVersion(), 
						message.getProtocolObject().getProtocol().getCode(), Constants.MSG_PROTOCOL_DIRECTION_RESPONSE);
			}
		}
		return null;
	}

	public SocketMessage getCurrentMessage() {
		return message;
	}

	public SocketChannel getChannel() {
		return channel;
	}

	public SocketObject getSocketObject() {
		return socketObject;
	}
}
